package org.reference.generic.operator;

import java.util.*;

import org.reference.generic.base.Item;
import org.reference.generic.base.Parameter;

/**
 * 
 */
public abstract class Node extends Item {

    /**
     * 
     */
    public Node(Parameter[] parameters) {
    	for (Parameter parameter : parameters) {
			if (parameter.getName().equalsIgnoreCase(Parameter.TYPE_MAX_DEPTH)) {
				maxDepth = parameter.getValueToInt();
			} else if (parameter.getName().equalsIgnoreCase(Parameter.TYPE_DEPTH)) {
				depth = parameter.getValueToInt();
			} else if (parameter.getName().equalsIgnoreCase(Parameter.TYPE_ARITY)) {
				arity = parameter.getValueToInt();
			}
		}
 
    	terminal = maxDepth == depth;
    	
//    	if (!terminal) {
//    		branches = new ArrayList<Node>();
//    		for (int i=0; i < arity; ++i) {
//    			branches.add(NodeFactory.getRandomNode(maxDepth, getChildDepth(), arity));
//    		}
//    	}
    }
    
	public int getDepth() {
		return depth;
	}

    /**
     * 
     */
    private Node root;

    /**
     * 
     */
    private int maxDepth;

    /**
     * 
     */
    private int depth;

    /**
     * 
     */
    private int arity;

    /**
     * 
     */
    private double resultValue;

    /**
     * 
     */
    protected boolean terminal;

    /**
     * 
     */
    protected ArrayList<Node> branches;

    protected void setResult(double value) {
    	//terminal = true;
    	//depth--;
    	resultValue = value;
    }
    /**
     * @return
     */
    public int getMaxDepth() {
        return maxDepth;
    }

    /**
     * @return
     */
    public int getArity() {
        return arity;
    }

    /**
     * @return
     */
    public double getResult() {
        return resultValue;
    }

    /**
     * @return
     */
    public boolean isTerminal() {
        return terminal;
    }

    /**
     * @param root
     */
    public void setRoot(Node root) {
    	this.root = root;
    }

    /**
     * @return
     */
    public Node getRoot() {
        return root;
    }

}